package com.dorje.sys.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.dorje.sys.entity.User;
import com.dorje.sys.service.MenuService;

import cc.ysblog.util.TreeUtil;

@Controller
@RequestMapping("/admin/")
public class AdminController {
	
	@Autowired
	MenuService menuService;
	
	@RequestMapping("index")
	public String index(){
		return "index";
	}
	
	@RequestMapping("menu")
	public void menu(HttpServletResponse response) throws IOException{
//		
//		String str = "["
//				+ "{\"id\":7,\"text\":\"系统管理\",\"checked\":false,\"selected\":false,\"children\":"
//				+ "[{\"id\":1,\"text\":\"用户管理\",\"checked\":false,\"selected\":false,\"attributes\":"
//				+ "{\"url\":\"/user/index\"}},"
//				+ "{\"id\":18,\"text\":\"用户登录日志查询\",\"checked\":false,\"selected\":false,\"attributes\":"
//				+ "{\"url\":\"/userloginlog.do\"}},{\"id\":162,\"text\":\"修改我的密码\",\"checked\":false,\"selected\":false,\"attributes\":{\"url\":\"/updateMySysPwd.do\"}},{\"id\":124,\"text\":\"系统日志查询\",\"checked\":false,\"selected\":false,\"attributes\":{\"url\":\"/sysloglist.do\"}},{\"id\":2,\"text\":\"角色管理\",\"checked\":false,\"selected\":false,\"attributes\":{\"url\":\"/rolesys.do\"}},{\"id\":3,\"text\":\"菜单管理\",\"checked\":false,\"selected\":false,\"attributes\":{\"url\":\"/menusys.do\"}},{\"id\":14,\"text\":\"部门管理\",\"checked\":false,\"selected\":false,\"attributes\":{\"url\":\"/deptsys.do\"}}],\"attributes\":{\"url\":\"/#\"}},{\"id\":164,\"text\":\"学生信息管理系统\",\"checked\":false,\"selected\":false,\"children\":[{\"id\":169,\"text\":\"学生信息分类统计\",\"checked\":false,\"selected\":false,\"attributes\":{\"url\":\"/stuStatistics.do\"}},{\"id\":165,\"text\":\"导入学生信息列表\",\"checked\":false,\"selected\":false,\"attributes\":{\"url\":\"/studentinfos.do\"}}],\"attributes\":{\"url\":\"/#\"}}]";
//		System.out.println(JSON.parseArray(str1));
//		response.getWriter().write(JSON.toJSONString(JSON.parseArray(str1)));
		
		User user = (User) SecurityUtils.getSubject().getPrincipal();
		
		Integer userid = user.getId();
		
		List<HashMap> menus=  TreeUtil.getLeftMenuTree(menuService.findLeftMenu());
//		System.out.println(maps);
		response.getWriter().write(JSON.toJSONString(menus));
		
	}
	
	@RequestMapping("main")
	public String main(){
		return "main";
	}
	
	@RequestMapping("noAuth")
	public String noAuth(){
		return "sys/noAuth";
	}
	
}
